var xml2js = require('xml2js');

var parser = new xml2js.Parser({
	mergeAttrs : true
});

var Response = function() {

};

Response.prototype.handle = function(data, session) {
	parser.parseString(data, function(e, response) {
		session.toClient(response);
		
//		response = response.response || {};
		
		// Response Hooks
		if(typeof(response.signInResponse) == 'object') { // Signin
			var signInResponse = response.signInResponse;
			
			if(signInResponse.id) {
				session.game = signInResponse.id;
			}
		} else if(typeof(response.createResponse) == 'object') { // Create
			var createResponse = response.createResponse;
			
			if(createResponse.id) {
				session.game = createResponse.id;
			}
		}
	});
};

module.exports = Response;
